package com.example;

import com.example.entity.Article;
import com.example.repository.ArticleRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Slf4j
@Service
public class ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    public Long createNewArticle() {
        Long articleId = IdTool.generate12DigitRandom();
        Long userId = IdTool.generate12DigitRandom();

        Article article = Article.builder().article_id(articleId).name(UUID.randomUUID().toString()).user_id(userId).build();
        try {
            articleRepository.save(article);
        }catch (Exception e){
            log.error("create Article error:{}, article: {}",e, article);
        }
        return article.getArticle_id();
    }

}
